/**************************************************************************
 *                                                                        *
 *         Copyright (c) 2007 by Sunplus mMedia Inc.                      *
 *                                                                        *
 *  This software is copyrighted by and is the property of Sunplus        *
 *  mMedia Inc. All rights are reserved by Sunplus mMedia Inc.  This      *
 *  software may only be used in accordance with the corresponding        *
 *  license agreement. Any unauthorized use, duplication, distribution,   *
 *  or disclosure of this software is expressly forbidden.                *
 *                                                                        *
 *  This Copyright notice MUST not be removed or modified without prior   *
 *  written consent of Sunplus mMedia Inc.                                *
 *                                                                        *
 *  Sunplus mMedia Inc. reserves the right to modify this software        *
 *  without notice.                                                       *
 *                                                                        *
 *  Sunplus mMedia Inc.                                                   *
 *  19-1, Innovation First Road, Science-Based Industrial Park,           *
 *  Hsin-Chu, Taiwan, R.O.C.                                              *
 *                                                                        *
 **************************************************************************/

#ifndef __TIMER_H__
#define __TIMER_H__
//------------------------------------------------------------------------------
//Constant
//------------------------------------------------------------------------------
//#define K_Timer0IntervalLo      030H            //  Timer0 interrput interval (HEX)
//#define K_Timer0IntervalHi      0f8H            //  = 10000 - 7D0 = F830
                                                //  = 7D0 * 1/2 us = 1 ms
//#define K_Timer0IntervalCompLo  033H            //  Timer0 interrput interval compensate 3 us (HEX)
//#define K_Timer0IntervalCompHi  0f8H            //  = 10000 - 7D0 + 3 = F833

#define K_Timer0IntervalLo      0e0H            //  Timer0 interrput interval (HEX)
#define K_Timer0IntervalHi      0b1H            //  = 10000 - 4e20 = b1e0
                                                //  = 4e20 * 1/2 us = 10 ms
#define K_Timer0IntervalCompLo  0c0H//0e3H            //  Timer0 interrput interval compensate 3 us (HEX)
#define K_Timer0IntervalCompHi  063H//0b1H            //  = 10000 - 4e20 + 3 = b1e3

#define K_TIMER_PERIOD          2               //  10ms/timer0 interrupt

#define K_Timer1IntervalLo	0x00 //0x60            //  Timer1 interrput interval (HEX)
#define K_Timer1IntervalHi	0x06 // 0xf0            // 2ms counter

//------------------------------------------------------------------------------
//External Link
//------------------------------------------------------------------------------
extern xdata UINT32 G_TimeStamp;
//extern xdata UINT8 G_KeyScan;
extern xdata UINT8 G_Timer0Stop;

typedef void (code* pTmrFunc)(UINT8*);


//------------------------------------------------------------------------------
//Function Prototype
//------------------------------------------------------------------------------
void TIMER0_Routine(void);
void TIMER0_Handler(void);
void TIMER0_Start(void);
void TIMER0_Stop(void);
void TIMER0_PowerOffCfg(UINT8 enable, UINT32 delay);
UINT8 TIMER0_PowerOffProcChk(void);

void DELAY_10us(void);
void DELAY_1ms(void);
void DELAY_1s(void);

void TIMER1_Config(UINT32 Period, pTmrFunc pFunc, UINT8* pFuncPara);
void TIMER1_Routine(void);
void TIMER1_Handler(void);
void TIMER1_Start(void);
void TIMER1_Stop(void);

extern pTmrFunc code timerFuncArray[];
extern pTmrFunc code intrFuncArray[];
#endif /*__TIMER_H__*/